package com.xuetang9.t9.xinhuaxia.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xuetang9.t9.xinhuaxia.beans.FirstCategory;
import com.xuetang9.t9.xinhuaxia.mappers.FirstCategoryMapper;
import com.xuetang9.t9.xinhuaxia.service.IFirstCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 李亚奇
 * @version 1.0
 * @desc TODO
 * @date 2020/3/1 13:44
 * @copyright liyq
 * @address 成都西部国际金融中心2栋2201
 **/
@Service
@Resource(name = "firstCategoryMapper")
public class FirstCategoryService implements IFirstCategoryService {
    @Autowired
    private FirstCategoryMapper firstCategoryMapper;
    @Override
    public boolean insert(FirstCategory firstCategory) {
        return firstCategoryMapper.insertSelective(firstCategory)>0;
    }

    @Override
    public boolean remove(Long id) {
        return firstCategoryMapper.deleteByPrimaryKey(id)>0;
    }

    @Override
    public boolean update(FirstCategory firstCategory) {
        return firstCategoryMapper.updateByPrimaryKeySelective(firstCategory)>0;
    }

    @Override
    public FirstCategory queryById(Long id) {
        return firstCategoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public FirstCategory queryByName(FirstCategory firstCategory) {
        return firstCategoryMapper.selectOne(firstCategory);
    }

    @Override
    public List<FirstCategory> queryAll() {
        return firstCategoryMapper.selectAll();
    }

    @Override
    public PageInfo<FirstCategory> queryByPage(int currentPage, int perPageSize) {
        PageHelper.startPage(currentPage,perPageSize);
        PageHelper.orderBy("fc_id desc");
        List<FirstCategory> firstCategories = firstCategoryMapper.selectAll();
        PageInfo<FirstCategory> pageInfo = new PageInfo<>(firstCategories);
        return pageInfo;
    }
}
